package com.chinamobile.iot.mqtt.spi.processor;

import javax.naming.event.ObjectChangeListener;

/**
 * Created by szl on 2017/7/12.
 */
public interface DataProcessor {

    /**
     * check if the event need to be saved
     *
     * @param clientId clientId
     * @param mqttId   mqttId
     * @return true if need, otherwise return false
     */
    boolean needToSaveEvent(String clientId, String mqttId);

    /**
     * need
     *
     * @param clientId
     * @param mqttId
     * @param topic
     * @param payload
     * @return
     */
    boolean needToSaveData(String clientId, String mqttId, String topic, byte[] payload);

    /**
     * get the mqtt Id of the data， it may dons't equal param mqttId， because may be it is from the topic
     *
     * @param clientId the clientId of the connection
     * @param mqttId   the mqtt Id of the connection
     * @param topic    the topic of the data
     * @param payload  the payload of the data
     * @return mqttId of the data
     */
    String getDataId(String clientId, String mqttId, String topic, byte[] payload);

    /**
     * get the data object to save to kafka. it may add some filed to the payload. for example: mqttId, userId, and so on
     *
     * @param clientId the clientId of the connection
     * @param mqttId   the mqqId of the connection
     * @param topic    the topic of the data
     * @param payload  the payload of the data
     * @return the Object to save backend
     */
    Object createData(String clientId, String mqttId, String topic, byte[] payload);

    /**
     * create event object to save to kafka
     *
     * @param clientId the clientId of the connection
     * @param mqttId   the mqttId of the connection
     * @param event    the event type
     * @return event object
     */
    Object createConnEvent(String clientId, String mqttId, ClientEvent event);

    /**
     * create command status object to send to kafka.
     *
     * @param clientId
     * @param mqttId
     * @param commandId
     * @param cmdStatus
     * @return
     */
    Object createCommandEvent(String clientId, String mqttId, String commandId, CommandState cmdStatus);

    /**
     * create data event， data event mean receive a data from a client or route a data to some client
     * @param clientId the clientId
     * @param mqttId the mqttId
     * @param topic the topic
     * @param direction 1 mean receive a data from the client, -1 mean route a data to some client
     * @return the data event
     */
    Object createDataEvent(String clientId, String mqttId, String topic, int direction);
}
